from sqlalchemy.sql import func

from src.utils.models import db


class SocialAccount(db.Model):
    # sns账户
    __tablename__ = 'sys_social_account'
    sid = db.Column(db.Integer, primary_key=True)
    provider_id = db.Column(db.String(50))
    provider = db.Column(db.String(50))
    user_id = db.Column(db.Integer, db.ForeignKey('sys_user.id'))


class AuthInstance(db.Model):
    # 授权实例
    __tablename__ = 'sys_auth_instance'
    sid = db.Column(db.Integer, primary_key=True)
    window_name = db.Column(db.String(100), unique=True, nullable=False)  # auth window name
    provider = db.Column(db.String(32))  # auth type email,weibo,github,google
    # auth type email,weibo,github,google
    email = db.Column(db.String(50), nullable=True)
    code = db.Column(db.String(100), nullable=True)
    access_token = db.Column(db.String(300), nullable=True)
    expires = db.Column(db.Integer, nullable=True)
    expires_at = db.Column(db.Integer, nullable=True)
    provider_id = db.Column(db.String(50), nullable=True)
    is_logout = db.Column(db.Integer, nullable=False, default=1)
    create_time = db.Column(db.DateTime, default=func.now())

    def arg(self):
        print("windowName" + self.window_name + "::privder:" + self.provider)
